<!-- 用户详情 -->
<template>
  <view>
    <view class="company-profile-container">
      <!-- 顶部操作：补充关键词（仅特定公司类型显示） -->
      <view
        @click="perfect"
        v-if="id == '' && ![1, 3, 7, 8].includes(Number(company.company_type))"
        style="
          display: inline-block;
          padding: 8px 16px;
          background-color: #007aff;
          color: white;
          border-radius: 4px;
          text-align: center;
          font-size: 14px;
          margin: 10px 0;
        "
      >
        补充信息匹配关键词
      </view>

      <!-- 公司状态提示 -->
      <view v-if="company_type != 1">
        <view class="status-bar" v-if="id == ''">
          <u-alert
            :type="getStatusType(company.company_status)"
            :title="company.company_status_name || '信息'"
            fontSize="20"
          ></u-alert>
          <text v-if="company.company_status_note" class="status-note">
            原因：{{ company.company_status_note }}
          </text>
        </view>
        <!-- 公司基本信息卡片 -->
        <view class="card">
          <view class="card-header">
            <text class="header-text">公司基本信息</text>
          </view>
          <view class="card-body">
            <!-- 通用基本字段 -->
            <view class="info-item">
              <text class="label">公司名称：</text>
              <text class="value">{{ company.company_name || "--" }}</text>
            </view>
            <view
              class="info-item"
              v-if="[6].includes(Number(company.company_type))"
            >
              <text class="label">队伍名称：</text>
              <text class="value">{{ company.team_name || "--" }}</text>
            </view>
            <view class="info-item">
              <text class="label">公司类型：</text>
              <text class="value">{{ getCompanyTypeName || "--" }}</text>
            </view>
            <view
              class="info-item"
              v-if="
                [2, 3, 4, 5, 6, 7, 8].includes(Number(company.company_type))
              "
            >
              <text class="label">主营业务：</text>
              <text class="value">{{ company.main_ye_wu || "--" }}</text>
            </view>
            <!-- <view class="info-item">
              <text class="label">邀请码：</text>
              <text class="value">{{ company.parent_id || "--" }}</text>
            </view> -->
            <view class="info-item" v-if="company.tgcompany_name">
              <text class="label">推广公司：</text>
              <text class="value">{{ company.tgcompany_name || "--" }}</text>
            </view>

            <!-- 经营时间相关 -->
            <view
              class="info-item"
              v-if="[2, 3, 4, 5, 6, 7].includes(Number(company.company_type))"
            >
              <text class="label">经营开始时间：</text>
              <text class="value">{{ company.run_date || "--" }}</text>
            </view>
            <view
              class="info-item"
              v-if="[8].includes(Number(company.company_type))"
            >
              <text class="label">成立日期：</text>
              <text class="value">{{ company.register_date || "--" }}</text>
            </view>

            <!-- 物资工厂特有字段 -->
            <view class="info-item" v-if="company.company_type == '3'">
              <text class="label">主管单位：</text>
              <text class="value">{{ company.zhu_guan_company || "--" }}</text>
            </view>
            <view
              class="info-item"
              v-if="[8].includes(Number(company.company_type))"
            >
              <text class="label">会员单位数量：</text>
              <text class="value">{{ company.user_num || "--" }}</text>
            </view>
            <view class="info-item" v-if="company.company_type == '3'">
              <text class="label">主要客户：</text>
              <text class="value">{{ company.main_customer || "--" }}</text>
            </view>
            <view class="info-item" v-if="company.company_type == '3'">
              <text class="label">生产商品：</text>
              <text class="value">{{ company.make_goods || "--" }}</text>
            </view>
            <view class="info-item" v-if="company.company_type == '3'">
              <text class="label">经销商品：</text>
              <text class="value">{{ company.sale_goods || "--" }}</text>
            </view>
          </view>
        </view>

        <!-- 负责人信息卡片 -->
        <view class="card card-mt">
          <view class="card-header">
            <text class="header-text">负责人信息</text>
          </view>
          <view class="card-body">
            <view
              class="info-item"
              v-if="
                [2, 3, 4, 5, 6, 7, 8].includes(Number(company.company_type))
              "
            >
              <text class="label">负责人姓名：</text>
              <text class="value">{{ company.person_realname || "--" }}</text>
            </view>
            <view
              class="info-item"
              v-if="
                [2, 3, 4, 5, 6, 7, 8].includes(Number(company.company_type))
              "
            >
              <text class="label">负责人职务：</text>
              <text class="value">{{ company.person_duty || "--" }}</text>
            </view>
            <view
              class="info-item"
              v-if="
                [2, 3, 4, 5, 6, 7, 8].includes(Number(company.company_type))
              "
            >
              <text class="label">负责人手机号：</text>
              <text class="value">{{ company.person_mobile || "--" }}</text>
            </view>
          </view>
        </view>

        <!-- 联系人信息卡片 -->
        <view class="card card-mt">
          <view class="card-header">
            <text class="header-text">联系人信息</text>
          </view>
          <view class="card-body">
            <view
              class="info-item"
              v-if="
                [2, 3, 4, 5, 6, 7, 8].includes(Number(company.company_type))
              "
            >
              <text class="label">联系人姓名：</text>
              <text class="value">{{ company.linkman_realname || "--" }}</text>
            </view>
            <view
              class="info-item"
              v-if="
                [2, 3, 4, 5, 6, 7, 8].includes(Number(company.company_type))
              "
            >
              <text class="label">联系人职务：</text>
              <text class="value">{{ company.linkman_duty || "--" }}</text>
            </view>
            <view
              class="info-item"
              v-if="
                [2, 3, 4, 5, 6, 7, 8].includes(Number(company.company_type))
              "
            >
              <text class="label">联系人手机号：</text>
              <text class="value">{{ company.linkman_mobile || "--" }}</text>
            </view>
            <view
              class="info-item"
              v-if="
                [2, 3, 4, 5, 6, 7, 8].includes(Number(company.company_type))
              "
            >
              <text class="label">联系人邮箱：</text>
              <text class="value">{{ company.linkman_email || "--" }}</text>
            </view>
          </view>
        </view>

        <!-- 地址信息卡片 -->
        <view class="card card-mt">
          <view class="card-header">
            <text class="header-text">地址信息</text>
          </view>
          <view class="card-body">
            <view
              class="info-item"
              v-if="
                [2, 3, 4, 5, 6, 7, 8].includes(Number(company.company_type))
              "
            >
              <text class="label">所在地区：</text>
              <text class="value">{{ company.city_name || "--" }}</text>
            </view>
            <view
              class="info-item"
              v-if="
                [2, 3, 4, 5, 6, 7, 8].includes(Number(company.company_type))
              "
            >
              <text class="label">详细地址：</text>
              <text class="value">{{ company.city_address || "--" }}</text>
            </view>
          </view>
        </view>

        <!-- 关联标识卡片 -->
        <view class="card card-mt" v-if="company.company_type != 8">
          <view class="card-header">
            <text class="header-text">关联标识</text>
          </view>
          <view class="card-body">
            <view
              class="info-item"
              v-if="[2, 3, 4, 5, 6].includes(Number(company.company_type))"
            >
              <text class="label">三大电网：</text>
              <text class="value">{{ getDianNames || "--" }}</text>
            </view>
            <view
              class="info-item"
              v-if="[2, 3, 4, 5, 6].includes(Number(company.company_type))"
            >
              <text class="label">五大六小：</text>
              <text class="value">{{ getJiTuanNames || "--" }}</text>
            </view>
            <view class="info-item" v-if="company.company_type != '8'">
              <text class="label">外贸：</text>
              <text class="value">{{ getWaiMaoNames || "--" }}</text>
            </view>
          </view>
        </view>

        <!-- 营业执照卡片 -->
        <view
          class="card card-mt"
          v-if="
            [2, 4, 5, 6].includes(Number(company.company_type)) &&
            company.zi_zhi.length
          "
        >
          <view class="card-header">
            <text class="header-text">拥有资质</text>
          </view>
          <view class="card-body">
            <view class="license-images">
              <u-image
                v-for="(img, index) in company.zi_zhi"
                :key="index"
                :src="img.url || img.web_url"
                mode="widthFix"
                class="license-img"
                @click="previewImage(img.url || img.web_url)"
              ></u-image>
            </view>
          </view>
        </view>
        <view
          class="card card-mt"
          v-if="
            [2, 3, 4, 5, 6, 7].includes(Number(company.company_type)) &&
            company.company_license.length
          "
        >
          <view class="card-header">
            <text class="header-text">营业执照</text>
          </view>
          <view class="card-body">
            <view class="license-images">
              <u-image
                v-for="(img, index) in company.company_license"
                :key="index"
                :src="img.url || img.web_url"
                mode="widthFix"
                class="license-img"
                @click="previewImage(img.url || img.web_url)"
              ></u-image>
            </view>
          </view>
        </view>
        <view
          class="card card-mt"
          v-if="
            [2, 3, 4, 5, 6, 7, 8].includes(Number(company.company_type)) &&
            company.zi_zhi.length
          "
        >
          <view class="card-header">
            <text class="header-text">证书图片</text>
          </view>
          <view class="card-body">
            <view class="license-images">
              <u-image
                v-for="(img, index) in company.zheng_shu_img"
                :key="index"
                :src="img.url || img.web_url"
                mode="widthFix"
                class="license-img"
                @click="previewImage(img.url || img.web_url)"
              ></u-image>
            </view>
          </view>
        </view>
        <view
          class="card card-mt"
          v-if="
            [2, 3, 4, 5, 6, 7, 8].includes(Number(company.company_type)) &&
            company.zi_zhi.length
          "
        >
          <view class="card-header">
            <text class="header-text">更多资质</text>
          </view>
          <view class="card-body">
            <view class="license-images">
              <u-image
                v-for="(img, index) in company.zi_zhi_more_img"
                :key="index"
                :src="img.url || img.web_url"
                mode="widthFix"
                class="license-img"
                @click="previewImage(img.url || img.web_url)"
              ></u-image>
            </view>
          </view>
        </view>
        <!-- 重新申请按钮（仅“审核未通过”状态显示） -->
        <view class="action-buttons" v-if="company.company_status == '4'">
          <button class="btn primary" @click="handleReapply(1)">
            重新申请
          </button>
        </view>
      </view>
      <view v-else>
        <view class="status-bar" v-if="id == ''">
          <u-alert
            :type="getStatusType(companyFirst.company_status)"
            :title="companyFirst.company_status_name || '信息'"
            fontSize="20"
          ></u-alert>
          <text v-if="companyFirst.company_status_note" class="status-note">
            原因：{{ companyFirst.company_status_note }}
          </text>
        </view>
        <!-- 基本信息卡片 -->
        <view class="card">
          <view class="card-header">
            <u-icon name="account" color="#4A90E2" size="32"></u-icon>
            <text class="header-text">基本信息</text>
          </view>
          <view class="card-body">
            <view class="info-item">
              <text class="label">注册类型：</text>
              <text class="value">{{ getRoleNames || "--" }}</text>
            </view>

            <view class="info-item">
              <text class="label">真实姓名：</text>
              <text class="value">{{ companyFirst.realname || "--" }}</text>
            </view>
            <view class="info-item">
              <text class="label">工作单位：</text>
              <text class="value">{{ companyFirst.work_company || "--" }}</text>
            </view>
            <view class="info-item">
              <text class="label">职务：</text>
              <text class="value">{{ companyFirst.duty || "--" }}</text>
            </view>
            <view class="info-item">
              <text class="label">出生年月日：</text>
              <text class="value">{{ companyFirst.birthday || "--" }}</text>
            </view>
            <view class="info-item">
              <text class="label">性别：</text>
              <text class="value">{{ getGenderName || "--" }}</text>
            </view>
            <view class="info-item">
              <text class="label">学历：</text>
              <text class="value">{{ companyFirst.xue_li || "--" }}</text>
            </view>
            <view class="info-item">
              <text class="label">就读大学：</text>
              <text class="value">{{ companyFirst.university || "--" }}</text>
            </view>
            <view
              class="info-item"
              v-if="companyFirst.roles && companyFirst.roles.includes(3)"
            >
              <text class="label">教育经历：</text>
              <text class="value">{{ companyFirst.job_school || "--" }}</text>
            </view>
            <view class="info-item">
              <text class="label">手机号：</text>
              <text class="value">{{ companyFirst.mobile || "--" }}</text>
            </view>
            <view class="info-item">
              <text class="label">邮箱：</text>
              <text class="value">{{ companyFirst.email || "--" }}</text>
            </view>
          </view>
        </view>

        <!-- 地址信息卡片 -->
        <view class="card card-mt">
          <view class="card-header">
            <u-icon name="map" color="#4A90E2" size="32"></u-icon>
            <text class="header-text">地址信息</text>
          </view>
          <view class="card-body">
            <view class="info-item">
              <text class="label">所在地区：</text>
              <text class="value">{{ companyFirst.city_name || "--" }}</text>
            </view>
          </view>
        </view>

        <!-- 求职信息卡片（仅求职者显示） -->
        <view
          class="card card-mt"
          v-if="companyFirst.roles && companyFirst.roles.includes(3)"
        >
          <view class="card-header">
            <text class="header-text">求职信息</text>
          </view>
          <view class="card-body">
            <view class="info-item">
              <text class="label">专业专长：</text>
              <text class="value">{{
                companyFirst.job_zhuan_chang || "--"
              }}</text>
            </view>
            <view class="info-item">
              <text class="label">求职意向：</text>
              <text class="value">{{ companyFirst.job_want || "--" }}</text>
            </view>
            <view class="info-item">
              <text class="label">工作经历：</text>
              <text class="value">{{ companyFirst.job_history || "--" }}</text>
            </view>
            <view class="info-item">
              <text class="label">求职类型：</text>
              <text class="value">{{ getJobTypeName || "--" }}</text>
            </view>
            <view class="info-item">
              <text class="label">期望薪资：</text>
              <text class="value">{{
                companyFirst.job_salary ? companyFirst.job_salary + "元" : "--"
              }}</text>
            </view>
            <view class="info-item">
              <text class="label">自我介绍：</text>
              <text class="value">{{
                companyFirst.job_introduce || "--"
              }}</text>
            </view>
          </view>
        </view>

        <!-- 智库信息卡片 -->
        <view class="card card-mt" v-if="id == ''">
          <view class="card-header">
            <u-icon name="star" color="#4A90E2" size="32"></u-icon>
            <text class="header-text">智库信息</text>
          </view>
          <view class="card-body">
            <view class="info-item">
              <text class="label">是否加入智库：</text>
              <text class="value">{{
                companyFirst.join_is == 2
                  ? "愿意"
                  : companyFirst.join_is == 1
                  ? "不愿意"
                  : "--"
              }}</text>
            </view>
            <view class="info-item" v-if="companyFirst.join_is == 2">
              <text class="label">可贡献内容：</text>
              <text class="value">{{
                companyFirst.join_gong_xian || "--"
              }}</text>
            </view>
            <view class="info-item" v-if="companyFirst.join_is == 2">
              <text class="label">期望获得：</text>
              <text class="value">{{ companyFirst.join_why || "--" }}</text>
            </view>
          </view>
        </view>

        <!-- 居间业务卡片（仅居间人显示） -->
        <view
          class="card card-mt"
          v-if="
            companyFirst.roles && companyFirst.roles.includes(1) && id == ''
          "
        >
          <view class="card-header">
            <!-- <u-icon name="business" color="#4A90E2" size="32"></u-icon> -->
            <text class="header-text">居间业务</text>
          </view>
          <view class="card-body">
            <view class="info-item">
              <text class="label">可提供的居间业务：</text>
              <text class="value">{{ companyFirst.ye_wu || "--" }}</text>
            </view>
          </view>
        </view>

        <view class="action-buttons" v-if="id">
          <button class="btn primary" @click="dial(companyFirst.mobile)">
            拨打电话
          </button>
        </view>
        <!-- 重新申请按钮（仅“审核未通过”状态显示） -->
        <view class="action-buttons" v-if="companyFirst.company_status == 4">
          <button class="btn primary" @click="handleReapply(2)">
            重新申请
          </button>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, computed } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import {
  GetUserCompany,
  GetIndexDian,
  GetIndexJiTuan,
  GetIndexWaiMao,
  GetUserExt,
} from "@/api/userInfo";
import { showToast, showLoading, hideLoading } from "@/utils/toast";

// 加载状态
const loading = ref(true);

// 公司类型列表（与表单保持一致）
const companyTypeList = [
  "居间人",
  "工程公司",
  "物资工厂",
  "设计公司",
  "监理公司",
  "劳务公司",
  "物资贸易商",
  "行业协会",
];

// 关联数据列表（用于显示名称而非ID）
const dianList = ref([]);
const jiTuanList = ref([]);
const waiMaoList = ref([]);

// 公司信息状态管理
const company = ref({
  // 基础字段
  id: "",
  company_type: "", // 公司类型（"1"-"8"，字符串）
  company_name: "",
  parent_id: "", // 邀请码
  tgcompany_name: "", // 推广公司名称

  // 时间字段
  run_date: "", // 经营开始时间
  register_date: "", // 成立日期

  // 物资工厂特有字段
  zhu_guan_company: "", // 主管单位
  user_num: "", // 会员单位数量
  main_customer: "", // 主要客户
  make_goods: "", // 生产商品
  sale_goods: "", // 经销商品

  // 负责人信息
  person_realname: "", // 负责人姓名
  person_duty: "", // 负责人职务
  person_mobile: "", // 负责人手机号

  // 联系人信息
  linkman_realname: "", // 联系人姓名
  linkman_duty: "", // 联系人职务
  linkman_mobile: "", // 联系人手机号
  linkman_email: "", // 联系人邮箱

  // 地址信息
  city_code: [], // 所在地区编码
  city_address: "", // 详细地址
  city_long: "", // 经度
  city_lat: "", // 纬度

  // 关联标识
  dian_id: [], // 三大电网ID
  ji_tuan_id: [], // 五大六小集团ID
  wai_mao_id: [], // 外贸标识ID

  // 营业执照
  company_license: [], // 营业执照图片

  // 状态字段
  company_status: "", // 状态（"2"=审核中，"3"=通过，"4"=未通过）
  company_status_name: "",
  company_status_note: "",
});

const companyFirst = ref({
  parent_id: "",
  roles: [], // 角色数组：1=居间人，2=电力行业从业者，3=求职者
  realname: "", // 真实姓名
  work_company: "", // 工作单位
  duty: "", // 职务
  birthday: "", // 出生年月日
  sex: "", // 性别
  xue_li: "", // 学历
  university: "", // 大学
  mobile: "", // 手机号
  email: "", // 邮箱
  city_code: "", // 常住城市
  join_is: "", // 是否愿意加入智库：1=不，2=愿意
  join_gong_xian: "", // 加入智库可贡献
  join_why: "", // 通过平台获得
  ye_wu: "", // 居间业务
  job_zhuan_chang: "", // 专长
  job_school: "", // 教育经历
  job_history: "", // 工作经历
  job_want: "", // 求职意向
  job_type: "", // 1=专职，2=兼职，3=专兼职均可
  job_salary: "", // 工资
  job_introduce: "", // 自我介绍
  tgcompany_name: "", // 推广公司名称
});

const company_type = ref();
// 页面加载
const id = ref("");
onLoad(async (e) => {
  company_type.value = e.company_type;
  if (e.company_type == 1) {
    console.log(e.id);

    if (e.id) {
      id.value = e.id;
    }
    await first();
  } else {
    console.log("进来了1");

    if (e.id) {
      id.value = e.id;
    }
    await init();
  }
});
const first = async () => {
  try {
    console.log(id.value);

    const res = await GetUserExt({ wechat_user_id: id.value });
    // 确保roles是数组
    if (res.data && res.data.role) {
      res.data.roles = Array.isArray(res.data.role)
        ? res.data.role
        : [res.data.role];
      delete res.data.role;
    }
    companyFirst.value = res.data;
  } catch (error) {}
};
// 初始化数据
const init = async () => {
  try {
    loading.value = true;

    // 并行请求所有需要的数据
    const [companyRes, dianRes, jiTuanRes, waiMaoRes] = await Promise.all([
      GetUserCompany({ wechat_user_id: id.value }),
      GetIndexDian(),
      GetIndexJiTuan(),
      GetIndexWaiMao(),
    ]);

    // 处理公司数据
    if (companyRes.data) {
      const apiData = companyRes.data;
      company.value = {
        ...company.value,
        ...apiData,
        company_type: String(apiData.company_type || ""),
        company_status: String(apiData.company_status || ""),
        city_code: apiData.city_code
          ? Array.isArray(apiData.city_code)
            ? apiData.city_code
            : [apiData.city_code]
          : [],
        dian_id: apiData.dian_id
          ? Array.isArray(apiData.dian_id)
            ? apiData.dian_id
            : apiData.dian_id.split(",")
          : [],
        ji_tuan_id: apiData.ji_tuan_id
          ? Array.isArray(apiData.ji_tuan_id)
            ? apiData.ji_tuan_id
            : apiData.ji_tuan_id.split(",")
          : [],
        wai_mao_id: apiData.wai_mao_id
          ? Array.isArray(apiData.wai_mao_id)
            ? apiData.wai_mao_id
            : apiData.wai_mao_id.split(",")
          : [],
        company_license: apiData.company_license || [],
        linkman_realname:
          apiData.linkman_realname || apiData.linkman_realname || "",
        run_date: apiData.run_date || apiData.need_time || "",
        city_address: apiData.city_address || apiData.need_city_address || "",
        city_code: apiData.city_code || apiData.need_city_code || [],
      };
    }

    // 保存关联数据列表
    dianList.value = dianRes.data || [];
    jiTuanList.value = jiTuanRes.data || [];
    waiMaoList.value = waiMaoRes.data || [];
  } finally {
    loading.value = false;
  }
};
// 计算属性：获取性别名称
const getGenderName = computed(() => {
  switch (Number(companyFirst.value.sex)) {
    case 1:
      return "男";
    case 2:
      return "女";
    default:
      return "--";
  }
});

// 计算属性：获取求职类型名称
const getJobTypeName = computed(() => {
  switch (Number(companyFirst.value.job_type)) {
    case 1:
      return "全职";
    case 2:
      return "兼职";
    case 3:
      return "均可";
    default:
      return "--";
  }
});

// 计算属性：获取角色名称（支持多角色）
const getRoleNames = computed(() => {
  if (!companyFirst.value.roles || !companyFirst.value.roles.length) {
    return "--";
  }

  const roleMap = {
    1: "居间人",
    2: "电力行业从业",
    3: "求职者",
  };

  // 将角色ID转换为名称并去重
  const roleNames = [
    ...new Set(
      companyFirst.value.roles.map((role) => roleMap[Number(role)] || role)
    ),
  ];

  return roleNames.join("、");
});

// 计算属性：公司类型名称
const getCompanyTypeName = computed(() => {
  const typeIndex = Number(company.value.company_type) - 1;
  return companyTypeList[typeIndex] || "--";
});

// 计算属性：三大电网名称
const getDianNames = computed(() => {
  if (!company.value.dian_id.length) return "--";
  return company.value.dian_id
    .map((id) => {
      const item = dianList.value.find((item) => item.id == id);
      return item ? item.name : id;
    })
    .join("，");
});

// 计算属性：五大六小名称
const getJiTuanNames = computed(() => {
  if (!company.value.ji_tuan_id.length) return "--";
  return company.value.ji_tuan_id
    .map((id) => {
      const item = jiTuanList.value.find((item) => item.id == id);
      return item ? item.name : id;
    })
    .join("，");
});

// 计算属性：外贸名称
const getWaiMaoNames = computed(() => {
  if (!company.value.wai_mao_id.length) return "--";
  return company.value.wai_mao_id
    .map((id) => {
      const item = waiMaoList.value.find((item) => item.id == id);
      return item ? item.name : id;
    })
    .join("，");
});

// 状态类型映射
const getStatusType = (status) => {
  switch (status) {
    case "2":
      return "warning"; // 审核中
    case "3":
      return "primary"; // 审核通过
    case "4":
      return "error"; // 审核未通过
    default:
      return "info";
  }
};

// 补充关键词
const perfect = () => {
  uni.navigateTo({ url: "/pages_index/user/keyword" });
};

// 重新申请
const handleReapply = (e) => {
  if (e == 1) {
    const type = company.value.company_type;
    if (!type) {
      showToast("公司类型获取失败，无法重新申请");
      return;
    }
    uni.navigateTo({
      url: `/pages/newsreg/gcgs?company_type=${type}&id=${
        company.value.id || ""
      }`,
    });
  } else {
    // 处理多角色的重新申请，这里取第一个角色作为默认值
    const roles = companyFirst.value.roles || [];
    const type = roles.length ? Number(roles[0]) : null;

    if (!type) {
      showToast("类型获取失败，无法重新申请");
      return;
    }
    uni.navigateTo({
      url: `/pages/newsreg/personage?id=${companyFirst.value.id}`,
    });
  }
};

const dial = async (e) => {
  // 获取手机号（根据你的实际数据结构获取）
  const phoneNumber = e;

  if (!phoneNumber) {
    uni.showToast({
      title: "手机号不能为空",
      icon: "none",
    });
    return;
  }

  // 检查手机号格式
  if (!/^1[3-9]\d{9}$/.test(phoneNumber)) {
    showToast("请输入正确的手机号");
    return;
  }

  try {
    // 微信小程序拨打电话API
    uni.makePhoneCall({
      phoneNumber: phoneNumber,
      success: () => {
        console.log("拨打电话成功");
      },
      fail: (err) => {
        console.error("拨打电话失败:", err);
        showToast("拨打电话失败");
      },
    });
  } catch (error) {
    console.error("拨打电话异常:", error);
    showToast("拨打电话异常");
  }
};

// 预览图片
const previewImage = (url) => {
  uni.previewImage({
    urls: [url],
  });
};
</script>

<style lang="scss">
.company-profile-container {
  padding: 20rpx;
  background-color: #f5f5f5;
  min-height: 100vh;
}

.status-bar {
  padding: 20rpx;
  margin-bottom: 20rpx;
  border-radius: 8rpx;
  color: #fff;
  font-weight: bold;
  display: flex;
  flex-direction: column;

  .status-note {
    font-size: 24rpx;
    margin-top: 10rpx;
    color: black;
    opacity: 0.8;
  }
}

.card {
  background-color: #fff;
  border-radius: 12rpx;
  margin-bottom: 20rpx;
  overflow: hidden;

  .card-header {
    padding: 20rpx;
    font-weight: bold;
    border-bottom: 1rpx solid #eee;
    background-color: #f9f9f9;
    display: flex;
    align-items: center;
  }

  .card-body {
    padding: 20rpx;
  }
}

.info-item {
  display: flex;
  margin-bottom: 16rpx;
  font-size: 28rpx;

  &:last-child {
    margin-bottom: 0;
  }

  .label {
    color: #666;
    width: 180rpx;
  }

  .value {
    flex: 1;
    color: #333;
  }
}

.action-buttons {
  padding: 20rpx 0;
  display: flex;

  .btn {
    flex: 1;
    height: 80rpx;
    line-height: 80rpx;
    border-radius: 40rpx;
    font-size: 30rpx;

    &.primary {
      background-color: #409eff;
      color: #fff;
    }
  }
}

.card-mt {
  margin-top: 20rpx;
}

.header-text {
  margin-left: 10rpx;
  font-size: 30rpx;
}
</style>
